<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="/basejsp.jspf" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body style="background: url('img/0407.jpg') no-repeat;  background-size:1278px 670px">
	
	<form action="user.action?methodName=toUpdatePassword" method="post" >
	<br /><br /><h2 style="color: white;">找回密码</h2>
		<table align="center" >
			<tr>
				<td align="left" style="color: white;">用户名：</td>
				<td align="left" >
					<input type="text" placeholder="请输入注册的用户名"  name="userName" /><b><span id="resultUsername" style="color: red;"></span></b>
					<input type="hidden" name="userid" value="userName"/>
				</td>
			</tr>
			<tr>
				<td align="left" style="color: white;">邮箱：</td>
				<td align="left">
					<input type="text" placeholder="请输入注册的邮箱" name="email"/><b><span id="resultEmail" style="color: red;"></span></b>
				</td>
			</tr>
			 <tr>
				<td align="left" style="color: white;">验证码：</td>
				<td align="left">
					<input type="text" style="height: 25px;" placeholder="请输入验证码" name="yanzheng" />
					
					<input type="button" value="发送验证码" onclick="dianji()" />
					
				</td>
			</tr>
			 
		</table>
		<br />
		<div style="margin-left: 20px" >
			<input type="submit" value="下一步" style="color: black;margin-right: 40px" id="next"/>
			<input type="button" value="返回" onclick="window.location='doLogin.action?methodName=toLogin'" style="color: black;"/>
		</div>
	</form>
	
	
</body>

	
	<script type="text/javascript">
	/*验证验证码是否正确  */
 	$(function() {
		var code="${yzm}";
		$("#next").click(function() {
		var yanzheng=$("input[name='yanzheng']").val();
		alert(code);
		if(code==yanzheng) {
			 $("form").attr("action","user.action?methodName=toUpdatePassword").submit();  
				
		}else{
			alert("验证码错误，请重新输入！");
			$("#input").html("");
			return false;
		}
			
		});
	}); 
	
	
	
	
	
	
	
	
	
	/*判断邮箱格式是否正确  */
		 $(function() {
			 
			$("form").click(function(){
				
				var userName = $("input[name='userName']").val();
				var Email = $("input[name='email']").val();
				var regEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
				var yanzheng=$("input[name='yanzheng']").val();
				var code="${yz}"; 
				
				if(userName == "") {
					$("#resultUsername").text("请输入用户名！");
					return false;
				}else if(userName.length<5||userName.length>20) {
					$("#resultUsername").text("用户名长度必须是5至20之间！");
					return ;
				}
				
				/*验证用户名是否已存在  */
				$("input[name='userName']").blur(function() {
					$("#resultUsername").text("");
					var uname=$(this).val();
					$.ajax({
						type:"post",
						url:"user.action?methodName=ajaxResetPassword",
						data:{"userName":uname},
						success:function(resultData){
							if(!resultData) {
								$("#resultUsername").text("该用户名不存在，请重新输入！");
								return;
							}else{
								$("#resultUsername").text("√");
							}
						}
					});
				});
				
				
				if(Email == "") {
					$("#resultEmail").text("请输入的邮箱!");
                    return false;
				}else if (!regEmail.test(Email)) {
					$("#resultEmail").text("对不起，您输入的邮箱格式不正确!");
                     return false;
				}
				
				/*验证邮箱是否已存在  */
				$("input[name='email']").blur(function() {
					$("#resultEmail").text("");
					var mail=$("input[name='email']").val();
					$.ajax({
						type:"post",
						url:"user.action?methodName=ajaxResetPassword",
						data:{"email":mail},
						success:function(resultData){
							if(!resultData) {
								$("#resultEmail").text("该邮箱不存在，请重新输入！");
								return;
							}else{
								$("#resultEmail").text("√");
							}
						}
					});
				});
				
				/* if(yanzheng=="") {
					alert("请输入验证码！");
					return;
				} */
			}); 
		 });
	
	

		
		
		
		
		
	</script>
	<!--发送邮箱验证码  -->
	<script type="text/javascript">
		function dianji(){
			var email = $("input[name='email']").val();
			
			$.post("user.action?methodName=yzEmail","email="+email,function(data){
				if(data!="cuowu"){
					alert("验证码已发送，请查收！");
					
				}else{
					alert("邮箱发送失败！请稍后重试！");
				}
			});
			
			
			
		}
		
	
	
	</script>
	
	
	

</html>